/*
   Copyright (c) 2023 李伟国
   learner-platform is licensed under Mulan PSL v2.
   You can use this software according to the terms and conditions of the Mulan PSL v2. 
   You may obtain a copy of Mulan PSL v2 at:
               http://license.coscl.org.cn/MulanPSL2 
   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
   See the Mulan PSL v2 for more details. 
*/

package cn.platform.controller;

import cn.platform.entity.Label;
import cn.platform.response.ResponseData;
import cn.platform.response.SuccessResponseData;
import cn.platform.service.ILabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "label")
public class LabelController {
    @Autowired
    private ILabelService labelService;

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public ResponseData getList(){
        return new SuccessResponseData(labelService.findAll());
    }

    @RequestMapping(value = "/", method = RequestMethod.POST)
    public ResponseData postLabel(@RequestBody Label label){
        return new SuccessResponseData(labelService.saveLabel(label));
    }

    @RequestMapping(value = "/", method = RequestMethod.PUT)
    public ResponseData putLabel(@RequestBody Label label){
        return new SuccessResponseData(labelService.updateById(label));
    }

    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    public ResponseData deleteLabel(@RequestBody Label label){
        return new SuccessResponseData(labelService.deleteLabel(label));
    }

    @RequestMapping(value = "/reset", method = RequestMethod.POST)
    public ResponseData resetLabel(@RequestBody Label label){
        return new SuccessResponseData(labelService.resetLabel(label));
    }
}
